package java_thread;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class demo_18_setPriority {
    public static void main(String[] args) {
        running_18 running = new running_18();
        Thread thread1 = new Thread(running);
        Thread thread2 =  new Thread(running);
        thread1.setPriority(10);
        thread2.setPriority(1);
        thread1.start();
        thread2.start();
    }
}

class running_18 implements Runnable{
    static int i = 0;
    List list = new CopyOnWriteArrayList();
    @Override
    public void run() {
        while (1==1){
            synchronized (list){
                list.add(i++);
                System.out.println("线程"+Thread.currentThread().getName()+"执行...");
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}